package com.xingzhe.pengji.thread.pool;

public class ThreadPoolTest {

	public static void main(String[] args) throws InterruptedException {
		ThreadPool threadPool = new ThreadPool(20); // 创建一个有个3工作线程的线程池
		Thread.sleep(500); // 休眠500毫秒,以便让线程池中的工作线程全部运行
		// 运行任务
		//for (int i = 0; i <= 500; i++) { // 创建6个任务
			//System.out.println(i);
			threadPool.execute(createTask(2));
			threadPool.execute(createTask1(1));
		//}
		threadPool.waitFinish(); // 等待所有任务执行完毕
		threadPool.closePool(); // 关闭线程池

	}

	private static Runnable createTask(final int taskID) {
		return new Runnable() {
			public void run() {
				// System.out.println("Task" + taskID + "开始");
				System.out.println("Hello world");
				// System.out.println("Task" + taskID + "结束");
			}
		};
	}
	
	private static Runnable createTask1(final int taskID) {
		return new Runnable() {
			public void run() {
				// System.out.println("Task" + taskID + "开始");
				System.out.println("Hello world1");
				// System.out.println("Task" + taskID + "结束");
			}
		};
	}
}